
function Results = print_results(results,dnames,rfe,nb,rcoeffs,sstage)

KR = length(rfe);
KD = length(dnames);

colNames = {'Estimate', 'StdError', 'pValue'};

if sstage == 0

    rowNames = [cellfun(@(t)['MP x ',t],dnames,'UniformOutput',0),...
        cellfun(@(t)['NA x ',t],dnames,'UniformOutput',0),...
        cellfun(@(t)['PVEM x ',t],dnames,'UniformOutput',0),...
        cellfun(@(t)['PRI x ',t],dnames,'UniformOutput',0),...
        cellfun(@(t)['PAN x ',t],dnames,'UniformOutput',0)];
    results([1:3+KR,3+KR+KD+(1:3+KR),2*(3+KR+KD)+(1:2+KR),...
        2*3+2+3*(KR+KD)+(1:2+KR),2*(3+2)+4*(KR+KD)+(1:3+KR)],:) = []; % remove FEs
    
    if isempty(rcoeffs)

        csnames = {'spending'};
        cs2names = {'spending^2'};
        if nb == 0
            rowNames = [csnames,cs2names,'log_lagged_vote_share',rowNames];
            results = results([end-1,end,end-2,1:end-3],:); % rearrange
        else
            rowNames = [csnames,cs2names,'neighbors_spending','log_lagged_vote_share',rowNames];
            results = results([end-1,end,end-2,end-3,1:end-4],:);
        end

    else

        csnames = [{'spending'},{'sigma_spending'}];
        cs2names = [{'spending^2'},{'sigma_spending^2'}];
        if nb == 0
            rowNames = [csnames,cs2names,'log_lagged_vote_share',rowNames];
            results = results([end-3,end-1,end-2,end,end-4,1:end-5],:);
        else
            rowNames = [csnames,cs2names,'neighbors_spending','log_lagged_vote_share',rowNames];
            results = results([end-3,end-1,end-2,end,end-4,end-5,1:end-6],:);
        end

    end

else

    rowNames = [cellfun(@(t)['PVEM x ',t],dnames,'UniformOutput',0),...
        cellfun(@(t)['PRI x ',t],dnames,'UniformOutput',0)];
    rowNames = ['log_lagged_vote_share',rowNames];
    results([1:2+KR,2+KR+KD+(1:2+KR)],:) = []; % remove FEs
    results = results([end,1:end-1],:); % rearrange

end

Results = array2table(results,'RowNames',rowNames,'VariableNames',colNames(1:size(results,2)));
Results.Properties.DimensionNames{1} = 'Coefficient';



